#include<stdio.h>
#include<unistd.h>
#include<sys/types.h>

int global_val = 100;

int main(){
  printf("进程执行\n");
  int flag = fork();
  if(flag < 0){
    perror("fork");
    return 1;
  }
  else if(flag == 0){
    while(1){
      printf("global_val的变化：%d -> %d\n",global_val, global_val + 10);
      //修改变量
      global_val += 10;
      printf("我是一个子进程，pid是%d, ppid是%d\n", getpid(), getppid());
      sleep(1);
    }
  }
  else{
    while(1){
      printf("我是一个进程，pid是%d, ppid是%d\n", getpid(), getppid());
      printf("global_val的值是%d\n", global_val);
      sleep(1);
    }
  }
  return 0;
}
